package com.itcoon.cloud.framework.ex;

import org.springframework.util.CollectionUtils;

import java.util.Collection;
import java.util.Map;

public interface Assertion {

    static <T> Raiser assertNull(T t){
        return assertTrue(t == null);
    }

    static Raiser assertEmpty(String s){
        return assertTrue(s.isEmpty());
    }

    static <T> Raiser assertEmpty(Collection<T> collection){
        return assertTrue(CollectionUtils.isEmpty(collection));
    }

    static <T> Raiser assertNotNull(T t) {
        return assertTrue(t != null);
    }

    static Raiser assertNotEmpty(String s) {
        return assertTrue(s.trim().length() != 0);
    }

    static Raiser assertNotBlank(String s) {
        return assertTrue(s != null && s.trim().length() != 0);
    }

    static <T> Raiser assertNotEmpty(Collection<T> collection) {
        return assertTrue(collection != null && collection.size() > 0);
    }

    static <K,V> Raiser assertNotEmpty(Map<K, V> map) {
        return assertTrue(map!=null && map.size() > 0);
    }

    static Raiser assertTrue(boolean flag) {
        return new AssertHandler(flag);
    }

}
